package com.my.createtype.singletion;
/*
 * safety singletion
 */
public class SafeSingletion {

	private static SafeSingletion s;
	
	private SafeSingletion() {
		System.out.println("SafeSingletion.SafeSingletion()");
	};
	
	// 这样就能保证线程安全
	public static SafeSingletion getInstance() {
		// 这种效率更高
		if(s == null) {
			synchronized (SafeSingletion.class) {
				s = new SafeSingletion();
			}
		}
		return s;
/*		synchronized (SafeSingletion.class) {
			if(s == null) {
				s = new SafeSingletion();
			}
			return s;
		}
*/	}

}
